#pragma once 
#include <iostream>
#include <pthread.h>
//简易地封装锁接口
namespace MutexModule
{
    class Mutex
    {
        public:
        Mutex()
        {
            pthread_mutex_init(&_mutex,nullptr);
        }
        void lock()
        {
            int n = pthread_mutex_lock(&_mutex);
            //加锁
        }
        void unlock()
        {
            int n = pthread_mutex_unlock(&_mutex);
        }
        pthread_mutex_t* get()
        {
            return &_mutex;
        }
        ~Mutex()
        {
            pthread_mutex_destroy(&_mutex);
        }
        private:
        pthread_mutex_t _mutex;
    };
    class lockguard
    {
        public:
        lockguard(Mutex &mutex):_mutex(mutex)
        {
            _mutex.lock();
        }
        ~lockguard()
        {
            _mutex.unlock();//用于自动解锁
        }
        private:
        Mutex &_mutex;
    };
   

}